package com.example.animationviewdemo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class MySecondAnimViewAdapter extends BaseAnimViewAdapter {
	private Context context;
	private List<Item> list;
	private Random random;
	private LayoutInflater inflater;
	public MySecondAnimViewAdapter(Context context) {
		this.context = context;
		inflater = LayoutInflater.from(context);
		list = new ArrayList<Item>();
		random = new Random(System.currentTimeMillis());
		for (int i = 0; i < 100; ++i) {
			int type = random.nextInt(2);
			Item object = new Item();
			object.setType(type);
			object.setTitle(String.valueOf(random.nextLong()));
			object.setContent(UUID.randomUUID().toString());
			list.add(object);
		}
	}

	@Override
	public int getItemViewType(int position) {
		return list.get(position).getType();
	}

	@Override
	public int getCount() {
		if (list == null || list.size() == 0)
			return 0;
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		if (list == null || list.size() == 0)
			return null;
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Item item = (Item) getItem(position);
		if(item.getType() == 0) {
			if(convertView == null) {
				convertView = inflater.inflate(R.layout.anim_layout, null);
			}
			TextView textView = (TextView) convertView.findViewById(R.id.text);
			textView.setText(item.getTitle());
		} else if(item.getType() == 1) {
			if(convertView == null) {
				convertView = inflater.inflate(R.layout.anim_layout2, null);
			}
			TextView textView1 = (TextView) convertView.findViewById(R.id.text1);
			textView1.setText(item.getTitle());
			TextView textView2 = (TextView) convertView.findViewById(R.id.text2);
			textView2.setText(item.getContent());
		}
		return convertView;
	}

	@Override
	public int getViewTypeCount() {
		return 2;
	}

}
